<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo $this->lang->line('sales_edit');?></h3>
<style>
    .fone_num_cls{
        width:20%;  vertical-align: top;
    }
</style>
<?php if (isset($flash_message)  && $flash_message!=NULL ): ?>
<div class="alert alert-success"><a class="close" sales-dismiss="alert">x</a><strong><?php echo $flash_message; ?></strong></div>
<?php endif; ?>
<div class="well">
    <?php echo form_open();?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php 
                //ten
                echo form_label($this->lang->line('name'), 'name');
                echo form_input(array('name' => 'name', 'id' => 'name', 'value' => (isset($sales->name))?$sales->name:'','placeholder'=>'Nhập họ và tên khách hàng vào đây'));
                echo form_error('name');
                //loại
                echo form_label($this->lang->line('sales_type'), 'type');
                echo form_dropdown('type', $this->sales_model->getListTypeCustomers(), (isset($sales->type))?$sales->type:'0');
                echo form_error('type');
                //phone
                echo form_label($this->lang->line('phone'), 'phone');
                echo form_input(array('type'=>'hidden','name' => 'phone', 'id' => 'phone', 'value' => (isset($sales->phone))?$sales->phone:'')).' ';
                echo form_input(array('disabled'=>'disabled', 'name' => 'phone_fake', 'id' => 'phone_fake', 'value' => (isset($sales->phone))?$sales->phone:'','class' => 'fone_num_cls')).' ';

                echo form_button(array('id'=>'callback','value' => '', 'name' => 'callback', 'content' => $this->lang->line('callback'),'class' => 'btn btn-primary')).' ';
                echo form_button(array('id'=>'callok','value' => '', 'name' => 'callok', 'content' => $this->lang->line('callok'),'class' => 'btn btn-primary')).' ';
                echo form_error('phone');
                
                //phone callstatus
                echo form_input(array('type'=>'hidden', 'name' => 'phone_callstatus', 'id' => 'phone_callstatus','value'=> (isset($sales))?$sales->phone_callstatus:''));
                //address
                echo form_label($this->lang->line('address'), 'address');
                echo form_input(array('name' => 'address', 'id' => 'address', 'value' => (isset($sales->address))?$sales->address:'0','placeholder'=>'Nhập địa chỉ khách hàng'));
                echo form_error('address');
                 //Email
                echo form_label($this->lang->line('email'), 'email');
                echo form_input(array('name' => 'email', 'id' => 'email', 'value' => (isset($sales->email))?$sales->email:'0','placeholder'=>'Nhập Email khách hàng'));
                echo form_error('email');
                 //Tỉnh thành                                
                echo form_label($this->lang->line('province'), 'province');
                echo form_dropdown('province', $this->sales_model->getListProvince(), (isset($sales->province))?$sales->province:'0');
                echo form_error('province');
                //khu vực bay
                echo form_label($this->lang->line('area'), 'area');
                echo form_dropdown('area', $this->area_model->getListArea(), (isset($sales->area))?$sales->area:'');
                echo form_error('area');
                //phương tiện KM
                echo form_label($this->lang->line('communication'), 'communication');
                echo form_dropdown('communication', $this->area_model->getListCommunication(), (isset($sales->communication))?$sales->communication:'0');
                echo form_error('communication');
                //Đánh giá chất lượng cuộc gọi
                echo form_label($this->lang->line('callquality'), 'callquality');
                echo form_dropdown('callquality', $this->area_model->getListCallquality(), (isset($sales->callquality))?$sales->callquality:'0');
                echo form_error('callquality');
                //Đánh giá mất độ quan tâm của khách hàng
                echo form_label($this->lang->line('interested'), 'interested');
                echo form_dropdown('interested', $this->area_model->getListInterested(), (isset($sales->interested))?$sales->interested:'0');
                echo form_error('interested');
                //Tần suất sử dụng vé máy bay trong 1 tháng
                echo form_label($this->lang->line('frequency'), 'frequency');
                echo form_input(array('name' => 'frequency', 'id' => 'frequency', 'value' => (isset($sales->frequency))?$sales->frequency:'0'));
                echo form_error('frequency');
                //Ghi chú KH
                echo form_label($this->lang->line('note_customers'), 'note_customers');
                echo form_textarea(array('name' => 'note_customers', 'id' => 'note_customers', 'value' => (isset($sales->note_customers))?$sales->note_customers:'','rows'=>'5','placeholder'=>'Ý kiến của khách hàng ghi vào đây'));
                echo form_error('note_customers');
                //Ghi chú Nhân viên
                echo form_label($this->lang->line('note_staffs'), 'note_staffs');
                echo form_textarea(array('name' => 'note_staffs', 'id' => 'note_staffs', 'value' => (isset($sales->note_staffs))?$sales->note_staffs:'','rows'=>'5','placeholder'=>'Ghi chú sales ghi vào đây'));
                echo form_error('note_staffs');
                ?>
            </div>
        </div>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('save'),'class' => 'btn btn-success')); ?>
                <a href="<?php echo site_url('auth/sales/search/'); ?>" class="btn"><?php echo $this->lang->line('cancel')?></a>
        </div>
    <?php echo form_close();?>
</div>
<script> 
$(document).ready(function() {
        var call = <?php echo $sales->phone_callstatus;?>;
        document.getElementById("phone_callstatus").value    = call;
        if(call == 3){
            $('#callback').attr('disabled','disabled');
            document.getElementById("callback").value       = call;
            document.getElementById("callok").value         = 4;
        } else {
            $('#callok').attr('disabled','disabled');
            document.getElementById("callback").value       = 3;
            document.getElementById("callok").value         = call;
        }
        
        $( "#callok" ).on('click',function() {
            document.getElementById("phone_callstatus").value    = $(this).val();
            $('#callok').attr('disabled','disabled');
            document.getElementById("callback").className   = "btn btn-primary";
            document.getElementById("callok").className     = "btn btn-danger";
        })
        
        $( "#callback" ).on('click',function() {
            document.getElementById("phone_callstatus").value    = $(this).val();
            $('#callback').attr('disabled','disabled');
            document.getElementById("callback").className   = "btn btn-danger";
            document.getElementById("callok").className     = "btn btn-primary";
        })
});
</script>
<?php $this->load->view('templates/backend/footer'); ?>